package com.tgpms.web.element.controller;

import com.tgpms.common.Result;
import com.tgpms.web.element.dto.WsElementRecordDto;
import com.tgpms.web.element.entity.WsElementRecord;
import com.tgpms.web.element.service.WsElementRecordService;
import com.tgpms.web.element.vo.WsElementRecordVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 检查要素记录表
 *
 * @author jl
 * @since 2020-11-05 09:40:32
 */
@RestController
@RequestMapping("/ev/wselementrecord")
public class WsElementRecordController {
    private final Logger log = LoggerFactory.getLogger(WsElementRecordController.class);

    @Autowired
    private WsElementRecordService wsElementRecordService;

    /**
     * 根据物资编码、校验单号查询检查要素记录表
     */
    @GetMapping("/list")
    public Result list(@RequestParam("commodityNumber") String commodityNumber, @RequestParam("examination") String examination) {
        log.info("查询检查要素记录接口接收到的参数为: " + commodityNumber + ", " + examination);

        Result result = new Result();
        List<WsElementRecordDto> WsElementRecordDtos = wsElementRecordService.getByCommodityNumber(commodityNumber, examination);
        result.setSuccess(true);
        result.setData(WsElementRecordDtos);
        return result;
    }

    /**
     * 新增wsElementRecord
     */
    @PostMapping("/save")
    public Result save(@RequestBody WsElementRecordVo WsElementRecordVo) {
        log.info("新增wsElementRecord接口接收到的参数为: " + WsElementRecordVo);

        Result result = new Result();
        wsElementRecordService.saveWsElementRecord(WsElementRecordVo);
        result.setSuccess(true);
        return result;
    }

    /**
     * 修改wsElementRecord
     */
    @PutMapping("/update")
    public Result update(@RequestBody WsElementRecord wsElementRecord) {
        log.info("修改wsElementRecord接口接收到的参数为: " + wsElementRecord);

        Result result = new Result();
        wsElementRecordService.updateById(wsElementRecord);
        result.setSuccess(true);
        return result;
    }

    /**
     * 根据物资编码删除wsElementRecord
     */
    @DeleteMapping("/delete")
    public Result delete(@RequestParam("commodityNumber") String commodityNumber, @RequestParam("examination") String examination) {
        log.info("删除wsElementRecord接口接收到的参数为: " + commodityNumber + ", " + examination);

        Result result = new Result();
        wsElementRecordService.removeByCommodityNumber(commodityNumber, examination);
        result.setSuccess(true);
        return result;
    }

}
